class Article{

    private config: any; // 定义私有变量 config

    constructor() {
        this.config = useRuntimeConfig(); // 在构造函数中初始化 config
    }

    async list(page:number = 1, pageSize:number=10, userId: string|null = null,randomFlag:boolean = false) {
        let url = `${this.config.public.apiUrl}article/${randomFlag ? 'random' : 'list'}?page=${page}&pageSize=${pageSize}`
        if (userId) {
            url += `&userId=${userId}`
        }

        const res = await $fetch(url, {
            headers: {
                // Authorization: `token ${config.githubToken}`
            }
        })

        return res
    }

    async getDetail(id: string) {
        let url = `${this.config.public.apiUrl}article/detail?id=${id}`
        const res = await $fetch(url)
        // console.log(res)
        return res;
    }

    async report(params:Record<any, any>) {
        const requestOptions = {
            baseURL: this.config.public.apiUrl, // 设置 baseURL
            method: "POST" as const,
            headers: {"X-APP-USER-TOKEN": ""},
            body: params,
        };
        const {data, error} = await useFetch("article/report", requestOptions);
        // console.log(res)
        return data;
    }
}

export default Article